package com.uzai.console.service.feign.impl;

import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.jsonvo.contract.ContractSignAddressJson;
import com.uzai.console.service.feign.UzaiContractFeignService;
import com.uzai.console.service.feign.UzaiImClientFeignService;
import com.uzai.console.service.feign.dto.ContractOpeDto;
import com.uzai.console.service.feign.dto.ContractRevokeDto;
import com.uzai.console.service.feign.dto.CreateContractDto;
import com.uzai.console.vo.contract.ContractAddressVo;
import com.uzai.console.vo.contract.ContractDownLoadVo;
import com.uzai.console.vo.contract.ContractSignInfoVo;
import com.uzai.console.vo.feign.contract.ContractSignFlowIdVo;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Auther: liuyanyan
 * @Date: 2024/05/22 10:39
 * @Description:
 */
@Component
public class UzaiContractFeignFallbackFactory implements FallbackFactory<UzaiContractFeignService> {

    private static Logger logger = LoggerFactory.getLogger(UzaiContractFeignFallbackFactory.class);
    @Override
    public UzaiContractFeignService create(Throwable throwable) {
        return new UzaiContractFeignService() {
            @Override
            public UzaiRespVo<ContractSignFlowIdVo> createContract(CreateContractDto createContractDto) {
                UzaiRespVo<ContractSignFlowIdVo> uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(null);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> revokeContract(ContractRevokeDto contractRevokeDto) {
                UzaiRespVo<Object> uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(null);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<ContractDownLoadVo> getContractDownloadUrl(ContractOpeDto createContractDto) {
                UzaiRespVo<ContractDownLoadVo> uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(null);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<ContractSignInfoVo> getContractInfo(ContractOpeDto createContractDto) {
                logger.error("失败原因：{}",throwable);
                UzaiRespVo<ContractSignInfoVo> uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(null);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<ContractSignAddressJson> getContractSignUrl(ContractOpeDto createContractDto) {
                UzaiRespVo<ContractSignAddressJson> uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(null);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }
        };
    }
}
